#include<iostream>
#include<cstdio>
using namespace std;
string s[1011];
int da[1011];
int m,sk=0;
string cz,sx;
/*
10
Server 192.168.1.1:80
Client 192.168.1.1:80
Client 192.168.1.1:8080
Server 192.168.1.1:80
Server 192.168.1.1:8080
Server 192.168.1.999:0
Client 192.168.1.1.8080
Client 192.168.1.1:8080
Client 192.168.1.1:80
Client 192.168.1.999:0
*/
bool ff(string x)
{
	int kdian=0,duan=0;
	bool flag=false,f1=false;
	for(int i=1;i<x.length()-1;i++)
	{
		if(x[i]=='.'||x[i]==':')
		{
			if(x[i-1]=='.'||x[i-1]==':'||x[i+1]=='.'||x[i+1]==':') return false;
		}
	}
	for(int i=0;i<x.length();i++)
	{
		if(x[i]=='0'&&(x[i+1]!='.'||x[i+1]!=':')&&flag==false)
		{
			return false;
			
		}
		else if(x[i]!='.'&&x[i]!=':')
		{
			flag=true;
			duan=duan*10+(x[i]-'0');
		}
		else if(x[i]=='.'||x[i]==':')
		{
			if(duan<0||duan>255)
			{
				return false;
			}
			duan=0;
			if(x[i]=='.')kdian++;
			flag=false;
			if(x[i]==':')
			{
				if(f1)
				{
					return false;
				}
				else f1=true;
			}
			
		}
	}
	if(kdian!=3||f1==false||duan<0||duan>65535) 
	{
		return false;
	}
	return true;
}
int main()
{
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	cin>>m;
	for(int i=0;i<m;i++)
	{
		bool f=false,f2=true,f3=true;
		cin>>cz>>sx;
		if(cz=="Client") f=true;
		if(ff(sx)==false)
		{
			cout<<"ERR"<<endl;
			continue;
		}
		else
		{
			for(int j=0;j<sk;j++)
			{
				if(s[j]==sx)
				{
					if(f)
					{
						cout<<da[j]<<endl;
						f3=false;
						break;
					}
					else
					{
						cout<<"FAIL"<<endl;
						f2=false;
					}
				}
			}
		}
		if(f&&f3)
		{
			cout<<"FAIL"<<endl;
			continue;
		}
		if(f2&&!f)
		{
			da[sk]=i+1;
			s[sk++]=sx;
			cout<<"OK"<<endl;
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
